package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.feign.seckill.SeckillFeignClient;
import com.atguigu.gmall.model.order.vo.OrderConfirmVo;
import com.atguigu.gmall.model.seckill.entity.SeckillGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class SeckillController {

    @Autowired
    SeckillFeignClient seckillFeignClient;

    @GetMapping("/seckill.html")
    public String toSeckill(Model model) {
        List<SeckillGoods> list = seckillFeignClient.getSecKillGoods().getData();
        model.addAttribute("list", list);
        return "seckill/index";
    }

    @GetMapping("/seckill/{skuId}.html")
    public String detail(@PathVariable Long skuId, Model model) {
        SeckillGoods data = seckillFeignClient.getDetail(skuId).getData();
        model.addAttribute("item", data);
        return "seckill/item";
    }

    @GetMapping("/seckill/queue.html")
    public String queue(Long skuId, String skuIdStr,Model model) {
        model.addAttribute("skuId", skuId);
        model.addAttribute("skuIdStr", skuIdStr);
        return "seckill/queue";
    }

    @GetMapping("/seckill/trade.html")
    public String trade(String skuIdStr,Model model) {
        OrderConfirmVo data = seckillFeignClient.getSeckillOrder(skuIdStr).getData();
        model.addAttribute("detailArrayList", data.getDetailArrayList());
        model.addAttribute("totalNum", data.getTotalNum());
        model.addAttribute("totalAmount", data.getTotalAmount());
        model.addAttribute("userAddressList", data.getUserAddressList());
        return "seckill/trade";
    }
}
